package com.baofu.paycore.service.factory.impl;

import com.baofu.paycore.manager.model.TransferBO;
import com.baofu.paycore.service.facade.model.transfer.CancelTransferDTO;
import com.baofu.paycore.service.factory.OrderFactory;
import com.baofu.paycore.service.factory.PayBaseFactory;
import com.baofu.paycore.service.processor.PayBaseProcessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * 转账撤销 组装工厂类
 *
 * <p/>
 *      1、组装转账模型
 * </p>
 * User: LZQ Date: 2016/04/20  Version: 1.0
 */
@Slf4j
@Service
public class CancelTransferFactoryImpl extends PayBaseFactory implements OrderFactory<CancelTransferDTO,TransferBO> {

    /**
     * 主单处理器
     */
    @Resource(name = "cancelTransferProcessor")
    private PayBaseProcessor commonProcessor;

    /**
     * 资金单处理器
     */
    @Resource(name = "cancelTransferFundProcessor")
    private PayBaseProcessor fundProcessor;

    @PostConstruct
    public void init(){
        processor.add(commonProcessor);
        processor.add(fundProcessor);
    }

    /**
     * 组装支付模型
     *
     * @param baseDTO 请求对象
     * @return 支付模型
     */
    @Override
    public TransferBO build(CancelTransferDTO baseDTO) {
        log.error("不支持此方法!:{}",baseDTO.getRequestBizNo());
        throw new UnsupportedOperationException("不支持此方法!");
    }

    /**
     * 带原交易 支付内部对象构建
     *
     * @param baseDTO  请求参数
     * @param oldPayBO 原支付模型
     */
    @Override
    public TransferBO build(CancelTransferDTO baseDTO, TransferBO oldPayBO) {
        TransferBO cancelTransferBO = new TransferBO();
        cancelTransferBO.setOldTransferBO(oldPayBO);
        buildBO(cancelTransferBO,baseDTO);
        return cancelTransferBO;
    }
}
